package com.interview.item.javabase.lambdaDemo;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.*;
import java.util.TimeZone;
import java.util.function.IntToDoubleFunction;

/**
 * @Author:zxh
 * @Description: java8新特性：lambda演示
 * @Date: 2020/3/30
 * @Modified By:
 */
public class Java8Tester {
    private static Logger logger = LoggerFactory.getLogger(Java8Tester.class);
final static String str = "34";
    /**
     * 1.lambda 表到式只能引用标记了final的外层局部变量，这就说明在lambda内部不能修改定义在域外的局部变量，否则会编译错误
     * 2.
     * @param args
     */
    public static void main(String[] args) {


        MathOperation operation = (int a,int b) -> a+b;
        System.out.println();
        GreetingService serviceOne = message -> System.out.println(message + str);


        System.out.println(TimeZone.getDefault().getOffset(System.currentTimeMillis())+"  ");
        System.out.println(System.currentTimeMillis());
        LocalDate.now();

        Clock clock = Clock.systemUTC();Instant instant = clock.instant();
        System.out.println("当前时间输出："+instant.toString());

        LocalDate now = LocalDate.now();
        System.out.println("localData: "+now.toString());

        LocalTime now1 = LocalTime.now();
        System.out.println("localTime:"+now1.toString());

        LocalDateTime now2 = LocalDateTime.now();
        System.out.println("localDateTime:"+now2.toString());

        /*ZonedDateTime now3 = ZonedDateTime.now(ZoneId.of("Asia/shanghai"));
        System.out.println("zonedDateTime:"+now3.toString());*/

       // Stream.of(1,2,4,3).reduce((acc,item) -> acc+=item
    }

        public static  void test(String args) {

        System.out.println("message:" + 23);
        String str = "23";//让lambda使用后默认为 final
        //Comparable<String> comparable =(str4) ->Integer.compare(str.length(),8);

        Java8Tester java8Tester = new Java8Tester();


        //类型姓名
        IntToDoubleFunction intToDoubleFunction = (int a) -> a;

        //不用类型声明
        MathOperation mathOperation = (a, b) -> a + b;

        //大括号中的返回语句
        MathOperation mathOperation1 = (int a, int b) -> {
            return a * b;
        };

        //没有大括号及返回语句
        MathOperation divsion = (int a, int b) -> a / b;
        logger.info("输出1：{}", java8Tester.operation(10, 5, mathOperation));
        logger.info("输出2：{}", java8Tester.operation(10, 5, mathOperation));
        logger.info("输出3：{}", java8Tester.operation(10, 5, mathOperation1));
        logger.info("输出4：{}", java8Tester.operation(10, 5, divsion));

        //不用括号
        GreetingService greetingService = message ->
                System.out.println("message:" + message);

        //用括号
        GreetingService greetingService1 = message ->
                System.out.println("message1:" + message);

        greetingService.sayMessage("google1");
        greetingService1.sayMessage("google2");
    }

    interface MathOperation {
        int operation(int a, int b);

    }

    interface MathOperationTwo {
        int operation(int a);
    }

    interface GreetingService {
        void sayMessage(String message);
    }



    private int operation(int a, int b, MathOperation mathOperation) {
        return mathOperation.operation(a, b);
    }
}
